<template>

<div>
  <div class="longin">
    <h1>登录界面</h1>
    <el-form ref="form" :model="form" label-width="80px">
  <el-form-item label="名字">
    <el-input v-model="form.username"></el-input>
  </el-form-item>
  <el-form-item label="密码">
    <el-input v-model="form.password"></el-input>
  </el-form-item>
  <!-- <el-form-item label="时间">
    <el-col :span="11">
      <el-date-picker type="date" placeholder="选择日期" v-model="form.date" value-format="yyyy-MM-dd" style="width: 100%;"></el-date-picker>
    </el-col>
  </el-form-item> -->
  <el-form-item>
    <el-button type="primary" @click="onSubmit">登录</el-button>
    <el-button>取消</el-button>
  </el-form-item>
</el-form>
  </div>

<!-- 模态框 -->
<div>
        <el-dialog  :title="title" :visible.sync="dialogFormVisible" @close="closeDialog">
        
        </el-dialog>
</div>

</div>


  
</template>


<script>

//导入axios
// import axios from 'axios'

  export default {
    data() {
      return {
        form: {
          username: '',
          password: '',
          date: '',
        },
        dialogFormVisible: false,
      //  dialogFormVisibletwo:false,
       title: ""

      }
    },
    methods: {
      onSubmit() {
        // console.log(this.form.uname);
        // console.log(this.form.upwd);
        // console.log(this.form.date1);
        //  axios.defaults.withCredentials=true;
        
        this.$axios.post("http://192.168.31.159:8601/auth/login",this.form)
        .then(resp=>{
            console.log(resp.data.code);
            if(resp.data.code==200){
              console.log(this.dialogFormVisible),
              (this.dialogFormVisible = true),
              (this.title = "登录成功"),
              (this.$router.push('/main'));
            }else if(resp.data.code==500){
               this.$message("用户名密码错误");
              //  (this.dialogFormVisible = true),
              //  (this.title = "用户名密码错误")
            }else if(resp.data.code==300){
               this.$message("无此用户");
              //  (this.dialogFormVisible = true),
              //  (this.title = "无此用户")
            }
            
            
        });
      }
    }
  }
</script>



